import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Form, DatePicker, Select } from 'antd'
import _ from 'loadsh'
import { Line, Cell, Split } from '@components/ApprovePre/Approve'

const { Item } = Form
const { Option } = Select
const layout = { labelCol: { flex: '136px' } }
export default class SecretaryInput extends Component {
  state = {
    keyTitleMap: {},
    fileList: []
  }

  initKeyTitleMap () {
    const map = {}
    const list = _.get(this.props.instance || {}, 'currentStep.vars', [])
    list.forEach(li => {
      map[li.key] = li.title
    })
    this.setState({
      keyTitleMap: map
    })
  }

  componentDidUpdate (prev) {
    if (this.props.instance !== prev.instance) {
      this.initKeyTitleMap()
    }
  }

  componentDidMount () {
    this.initKeyTitleMap()
  }

  render () {
    const { keyTitleMap } = this.state
    const { dictionaries } = this.props
    const closureType = dictionaries['结案类型'] || []
    return (
      <div>
        <Line>
          <Cell>
            <Item {...layout} label='发起秘书'>
              <span>{this.props.userInfo.realname}</span>
            </Item>
          </Cell>
          <Split />
          <Cell>
            <Item labelCol={{ flex: '128px' }} name={['vars', 'closure_type']} label={keyTitleMap.closure_type} rules={[{ required: true, message: `${keyTitleMap.closure_type}不能为空` }]}>
              <Select placeholder={`请选择${keyTitleMap.closure_type}`}>
                {closureType.map(li => {
                  return <Option key={li.title} value={li.title}>{li.title}</Option>
                })}
              </Select>
            </Item>
          </Cell>
          <Split />
          <Cell>
            <Item {...layout} name={['vars', 'closure_doc_datetime']} label={keyTitleMap.closure_doc_datetime} rules={[{ required: true, message: `${keyTitleMap.closure_doc_datetime}不能为空` }]}>
              <DatePicker placeholder={`请选择${keyTitleMap.closure_doc_datetime}`} style={{ width: '100%' }} />
            </Item>
          </Cell>
        </Line>
      </div>
    )
  }
}

SecretaryInput.proptypes = {
  caseDetail: PropTypes.object,
  userInfo: PropTypes.object,
  instance: PropTypes.object,
  formRef: PropTypes.object,
  dictionaries: PropTypes.object
}

SecretaryInput.defaultProps = {
  caseDetail: {},
  userInfo: {},
  instance: {},
  formRef: {},
  dictionaries: {}
}
